#include <bits/stdc++.h>
using namespace std;
const int maxn = 30+2;
int B[maxn][3], dp[maxn][3];
int N;
const int INF = 1<<30;

void cal(int &a, int &b, int i, int j){
    if(j==0) a = B[i][1], b = B[i][2];
    if(j==1) a = B[i][0], b = B[i][2];
    if(j==2) a = B[i][0], b = B[i][1];
}

int DP(int i, int j){
    int &ans = dp[i][j];
    if(ans > 0) return ans;
    int a, b, h;
    cal(a, b, i, j);
    h = B[i][j];
    ans = h;
    int maxx = 0;
    for (int k = 0; k < N; ++k) {
        for (int l = 0; l < 3; ++l) {
            int a2, b2;
            cal(a2, b2, k, l);
            if((a2 < a && b2 < b) || (a2 < b && b2 < a))
                maxx = max(maxx, DP(k, l));
//                ans = max(ans, ans + DP(k, l));
        }
    }
    ans += maxx;
    return ans;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int kase = 0;
    while (cin >> N && N) {
        for (int i = 0; i < N; ++i) {
            cin >> B[i][0] >> B[i][1] >> B[i][2];
        }
        int ans = 0;

        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < 3; ++j) {
                ans = max(ans, DP(i, j));
            }
        }
        cout << "Case " << ++kase << ": maximum height = " << ans << "\n";
    }
    return 0;
}